package com.leetcode.merci.lc008;

/**
 * Created by bowen on 2017/7/28.
 */
public class Solution {
    public int myAtoi(String str) {
        str.trim();
        char[] s=str.toCharArray();
        int l=str.length();
        if(l==0)
            return 0;
        if(s[l-1]=='+'||s[l-1]=='-')
            return 0;
        int result=0;
        int t=1;
        for(int i=l-1;i>=0;i--){
            if(s[i]==' ')
                s[i]='0';
            if((s[i]-'0'<0||s[i]-'0'>9)){
                if(i!=0)
                    return 0;
                continue;
            }
            else{
                result+=(s[i]-'0')*t;
            }
            t*=10;
        }
        if(s[0]=='-')
            return 0-result;
        return result;
    }

    public static void main(String[] args) {
        char a='A';
        int i=a;
        System.out.println(i);
    }
}